

export class Telegram {

    //the entity that sent this telegram
    sender:number = -1;

    //the entity that is to receive this telegram
    receiver:number = -1;

    //the message itself. These are all enumerated in the file
    //"MessageTypes.h"
    msg:number = -1;

    //messages can be dispatched immediately or delayed for a specified amount
    //of time. If a delay is necessary this field is stamped with the time 
    //the message should be dispatched.
    dispatchTime:number = -1;

    //any additional information that may accompany the message
    extraInfo:any = null;

    static clone(t:Telegram):Telegram {
        return new Telegram(t.dispatchTime, t.sender, t.receiver,t.msg, t.extraInfo);
    }

    static compare(t1:Telegram, t2:Telegram):number {
        if(t1.dispatchTime < t2.dispatchTime) return -1;
        else if(t1.dispatchTime > t2.dispatchTime) return 1;
        else return 0;
    }

    constructor(time:number,
            sender:number,
            receiver:number,
            msg:number,
            info?:any) {
        
        this.dispatchTime = time;
        this.sender = sender;
        this.receiver = receiver;
        this.msg = msg;
        this.extraInfo = info;
    }

    toString():string {
        return `time: ${this.dispatchTime}  Sender: ${this.sender}  Receiver: ${this.receiver}  Msg:${this.msg}`;
    }
}


//these telegrams will be stored in a priority queue. Therefore the >
//operator needs to be overloaded so that the PQ can sort the telegrams
//by time priority. Note how the times must be smaller than
//SmallestDelay apart before two Telegrams are considered unique.
export const SmallestDelay = 0.25;